#{extends 'TopicIdeaController/createTopic.html' /}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link href="../../../public/stylesheets/style_sheet.css"
	rel="stylesheet" type="text/css" />
<script type="text/javascript"
	src="/../../../public/javascripts/jquery.min.js"></script>
<script type="text/javascript"
	src="/../../../public/javascripts/jquery-ui.min.js"></script>
<script src="../../../public/javascript/jquery.js"
	type="text/javascript"></script>
<script src="../../../public/javascript/scripts.js"
	type="text/javascript"></script>
<link rel="stylesheet"
	href="../../../public/stylesheets/blitzer/jquery-ui-1.8.13.custom.css"
	type="text/css" media="screen" />
<script src="../../../public/javascripts/jquery-1.5.1.min.js"
        type="text/javascript"></script>

        <script src="../../../public/javascripts/jquery-ui-1.8.13.custom.min.js"
        type="text/javascript"></script>

#{get 'moreStyles' /}
<link rel="shortcut icon" type="image/png"
	href="@{'/public/images/ninjaIcon.png'}">
<script type="text/javascript"
	src="@{'/public/javascripts/fancybox/jquery.fancybox-1.3.4.pack.js'}"></script>
<link rel="stylesheet"
	href="@{'/public/javascripts/fancybox/jquery.fancybox-1.3.4.css'}"
	type="text/css" media="screen" />
<!-- <script type="text/javascript" src="../../../public/javascripts/jquery-1.4.2.js"></script>
    <script type="text/javascript" src=
    "../../../public/javascripts/jquery.ui.all.js" ></script>-->
<script type="text/javascript"
	src="../../../public/javascripts/jquery.jgrowl.js"></script>
<link rel="stylesheet"
	href="../../../public/javascripts/jquery.jgrowl.css" type="text/css" />

<!-- JAVA SCRIPT PARTIOTION START -->

<script type="text/javascript">
$(document).ready(function() {
	$(".frame").fancybox({

		'width' : '75%',

		'height' : '75%',

		'autoScale' : true,

		'transitionIn' : 'none',

		'transitionOut' : 'none',
		'type' : 'iframe',
	    'onClosed': function() {
		    parent.location.reload(true); 
		  }

     });
	
	$(".frameNoRefresh").fancybox({

		'width' : '100%',

		'height' : '100%',

		'autoScale' : true,

		'transitionIn' : 'none',

		'transitionOut' : 'none',

		'type' : 'iframe'





	});


});
	//plugin found on the internet
	function updateList() {

		//Adjust panel height
		$.fn.adjustPanel = function() {
			$(this).find("ul, .subpanel").css({
				'height' : 'auto'
			}); //Reset subpanel and ul height

			var windowHeight = $(window).height(); //Get the height of the browser viewport
			var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel
			var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)
			var ulAdjust = panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)

			if (panelsub >= panelAdjust) { //If subpanel is taller than max height...
				$(this).find(".subpanel").css({
					'height' : panelAdjust
				}); //Adjust subpanel to max height
				$(this).find("ul").css({
					'height' : ulAdjust
				}); //Adjust subpanel ul to new size
			} else if (panelsub < panelAdjust) { //If subpanel is smaller than max height...
				$(this).find("ul").css({
					'height' : 'auto'
				}); //Set subpanel ul to auto (default size)
			}
		};

		//Execute function on load
		$("#RequestJoinOrg").hide();

		$("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel
		$("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel

		//Each time the viewport is adjusted/resized, execute the function
		$(window).resize(function() {
			$("#chatpanel").adjustPanel();
			$("#alertpanel").adjustPanel();
		});

		//Click event on Chat Panel + Alert Panel
		$("#chatpanel a:first, #alertpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...
			if ($(this).next(".subpanel").is(':visible')) { //If subpanel is already active...
				$(this).next(".subpanel").hide(); //Hide active subpanel
				$("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
			} else { //if subpanel is not active...
				$(".subpanel").hide(); //Hide all subpanels
				$(this).next(".subpanel").toggle(); //Toggle the subpanel to make active
				$("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger
				$(this).toggleClass('active'); //Toggle the active class on the subpanel trigger
			}
			return false; //Prevent browser jump to link anchor
		});

		//Click event outside of subpanel
		$(document).click(function() { //Click anywhere and...
			$(".subpanel").hide(); //hide subpanel
			$("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger
		});
		$('.subpanel ul').click(function(e) {
			e.stopPropagation(); //Prevents the subpanel ul from closing on click
		});

		//Delete icons on Alert Panel
		$("#alertpanel li").hover(function() {
			$(this).find("a.delete").css({
				'visibility' : 'visible'
			}); //Show delete icon on hover
		}, function() {
			$(this).find("a.delete").css({
				'visibility' : 'hidden'
			}); //Hide delete icon on hover out
		});
	}

</script>

<script type="text/javascript">
	function showNotificationsNotification() {

		$.getJSON('@{usersController.DisplayNotificationPopID()}',

		{
			'userName' : "username"
		}, function(data) {
			if (data != null && data.result == "sizeNotEqualZero"
					&& data.NoNewNotification == "no") {

				$('#two').jGrowl(data.list);

			} else {

				alert("No Notifications available ");
			}
		});
	}
</script>

<script type="text/javascript">
	function showNotificationsID() {

		$
				.getJSON(
						'@{usersController.DisplayNotificationSID()}',

						{
							'userName' : "username"
						},
						function(data) {
							if (data != null
									&& data.result == "sizeNotEqualZero") {
								var list = {};
								list = data.list.split("&&");

								var total = "<h3><span>&ndash; </span>Notifications</h3><ul><li class=\"view\"><a href=\"#\">View All</a></li>";
								//<p><a href='#' onclick=\"show_iDev('"+ innerList[0]+ "')\">"+ innerList[0]+ "</a> "+innerList[1]+"</p>

								for ( var i = 0; i < list.length - 1 && i < 5; i = i + 1) {

									var innerList = {};
									innerList = list[i].split(",,,");
									total += "<li><a href=\"#\" class=\"delete\">X</a><p><a href='#' onclick=\"show_iDev('"
											+ innerList[0]
											+ "')\">"
											+ innerList[0]
											+ "</a> "
											+ innerList[1] + "</p></li>";

								}
								total += "</ul>";
								document.getElementById("notificationS").innerHTML = total;
								updateList()
							} else {
								alert("No Notifications available ");
							}
						});
	}
</script>


<script type="text/javascript">
<!--
	var currrent = "";
	$(function() {
		$.getJSON("@{Application.getId()}", function(data) {
			current = data.res;
		});
		$('#devCanDivInOrg').hide();
		$('#createEntityDiv').hide();
		$('#createSubEntityDiv').hide();
		$('#deleteEntityDiv').hide();
		$('#orgRequestDiv').hide();
		$('#devRequestDiv').hide();
		$('#devCanDivInEnt').hide();
	});

	function OnGoMenuFormLink(GoList) {
		var url = GoList.options[GoList.selectedIndex].value;
		//var target = GoList.options[GoList.selectedIndex].className;
		if (url == "CreateEn") {
			//prepare the data which is the organizations he can partiotion it
			document.getElementById("createEntityDiv").innerHTML = "";
			$
					.getJSON(
							'@{Application.getManagedOrganizations()}',
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("You arnot athurized to do that in any org :)");
								} else {
									alert(data.length)
									var total = "<p><label>please choose one from your organizations</label><select id=\"selavorg\">"
									for ( var i = 0; i < data.length; i = i + 1) {
										total += "<option selected value="+data[i].id+">"
												+ data[i].name + "</option>"
									}
									total += "</select></p>";
									total += "<p><input type=\"text\" id=\"newEntName\"/></p>";
									total += "<p><a href='#' onclick=\"createEntity()\">submit</a></p>";
									document.getElementById("createEntityDiv").innerHTML = total;
									$('#createEntityDiv').toggle(1000);
									$('#devCanDivInOrg').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').hide(1000);
									$('#devCanDivInEnt').hide(1000);
								}
							});

		} else if (url == "CreateSub") {
			$('#createSubEntityDiv').hide(1000);
			document.getElementById("createSubEntityDiv").innerHTML = "";
			$
					.getJSON(
							'@{Application.getManagedEntities()}',
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("You don't manage any entity to add a sub entity in :)");
								} else {
									var total = "<p><label>please choose one from your organizations</label><select id=\"selavent\">"
									for ( var i = 0; i < data.length; i = i + 1) {
										total += "<option selected value="+data[i].id+">"
												+ data[i].name + "</option>"
									}
									total += "</select></p>";
									total += "<p><input type=\"text\" id=\"newSubEntName\"/></p>";
									total += "<p><a href='#' onclick=\"createSubEntity()\">submit</a></p>";
									document
											.getElementById("createSubEntityDiv").innerHTML = total;
									$('#createEntityDiv').hide(1000);
									$('#devCanDivInOrg').hide(1000);
									$('#createSubEntityDiv').toggle(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').hide(1000);
									$('#devCanDivInEnt').hide(1000);
								}
							});

		} else if (url == "DelEn") {
			$('#deleteEntityDiv').hide(1000);
			document.getElementById("deleteEntityDiv").innerHTML = "";
			$
					.getJSON(
							'@{Application.getManagedEntities()}',
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("You don't manage any entity to delete it :)");
								} else {
									var total = "<p><label>please choose one from your entities</label><select id=\"selavent2\">"
									for ( var i = 0; i < data.length; i = i + 1) {
										total += "<option selected value="+data[i].id+">"
												+ data[i].name + "</option>"
									}
									total += "</select></p>";
									total += "<p><a href='#' onclick=\"delEntity()\">submit</a></p>";
									document.getElementById("deleteEntityDiv").innerHTML = total;
									$('#devCanDivInOrg').hide(1000);
									$('#createEntityDiv').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').toggle(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').hide(1000);
									$('#devCanDivInEnt').hide(1000);
								}
							});
		} else if (url == "CheckInviteOrg") {
			$('#orgRequestDiv').hide();

			$
					.getJSON(
							"@{Application.getRequestsRecievedForMyOrgz()}",
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("No New requests sent to join your organizations or your managed Entities");
								} else {
									document.getElementById("orgRequestDiv").innerHTML = "";
									for ( var i = 0; i < data.length; i = i + 1) {
										document
												.getElementById("orgRequestDiv").innerHTML += "<p>"
												+ data[i].name
												+ "<a href='#' onclick = \"acceptReq('"
												+ data[i].id
												+ "')\"> ACCEPT </a></p>";
									}
									$('#devCanDivInOrg').hide(1000);
									$('#createEntityDiv').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').toggle(1000);
									$('#devRequestDiv').hide(1000);
									$('#devCanDivInEnt').hide(1000);
								}
							});
		} else if (url == "CheckInviteDev") {
			$('#devRequestDiv').hide();
			$
					.getJSON(
							"@{Application.getRequestsSentToIdeaDeveloper()}",
							{
								'devId' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("No New requests has been sent to you");
								} else {
									document.getElementById("devRequestDiv").innerHTML = "";
									for ( var i = 0; i < data.length; i = i + 1) {
										document
												.getElementById("devRequestDiv").innerHTML += "<p>"
												+ data[i].name
												+ "<a href='#' onclick = \"acceptReq('"
												+ data[i].id
												+ "')\"> ACCEPT </a></p>";
									}
									$('#devCanDivInOrg').hide(1000);
									$('#createEntityDiv').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').toggle(1000);
									$('#devCanDivInEnt').hide(1000);
								}
							});
		} else if (url == "InviteDevToEntity") {
			$('#devCanDivInEnt').hide(1000);
			document.getElementById("devCanDivInEnt").innerHTML = "";
			$
					.getJSON(
							'@{Application.getManagedEntities()}',
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("You don't manage any entity to join developers in :)");
								} else {
									//alert(data.length);
									var total = "<p><label>please choose one from your entities</label><select id=\"selavent3\">"
									for ( var i = 0; i < data.length; i = i + 1) {
										total += "<option selected value="+data[i].id+">"
												+ data[i].name + "</option>"
									}
									total += "</select></p>";
									total += "<div id='ideaDevelopers'></div>";
									total += "<p><a href='#' onclick=\"getDevCanReqInEnt()\">submit</a></p>";
									document.getElementById("devCanDivInEnt").innerHTML = total;
									$('#devCanDivInEnt').toggle(1000);
									$('#devCanDivInOrg').hide(1000);
									$('#createEntityDiv').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').hide(1000);
								}
							});

		} else if (url == "InviteDevToOrganization") {
			$('#devCanDivInOrg').hide(1000);
			document.getElementById("devCanDivInOrg").innerHTML = "";
			$
					.getJSON(
							'@{Application.getManagedOrganizations()}',
							{
								'id' : current
							},
							function(data) {
								if (data == null || data.length == 0) {
									alert("You don't manage any Organization to invite developers in :)");
								} else {
									var total = "<p><label>please choose one from your organizations</label><select id=\"selorg3\">"
									for ( var i = 0; i < data.length; i = i + 1) {
										total += "<option selected value="+data[i].id+">"
												+ data[i].name + "</option>"
									}
									total += "</select></p>";
									total += "<div id='ideaDevelopers1'></div>";
									total += "<p><a href='#' onclick=\"getDevCanReqInOrg()\">submit</a></p>";
									document.getElementById("devCanDivInOrg").innerHTML = total;
									$('#devCanDivInOrg').toggle(1000);
									$('#devCanDivInEnt').hide(1000);
									$('#createEntityDiv').hide(1000);
									$('#createSubEntityDiv').hide(1000);
									$('#deleteEntityDiv').hide(1000);
									$('#orgRequestDiv').hide(1000);
									$('#devRequestDiv').hide(1000);
								}
							});
		}
	}
	function getDevCanReqInOrg() {
		var entId = document.getElementById('selorg3').options[document
				.getElementById('selorg3').selectedIndex].value
		document.getElementById('ideaDevelopers1').innerHtml = "";
		$('#ideaDevelopers1').hide(100);
		$
				.getJSON(
						"@{Application.getCanRequestIdeaDevelopersToOrganization()}",
						{
							'orgId' : entId
						},
						function(data) {
							if (data == null || data.length == 0) {
								alert("There are no developers you can invite to this organization");
							} else {
								var total = "";
								for ( var i = 0; i < data.length; i = i + 1) {
									if (data[i].id == -1) {
										total += "<p>" + data[i].name + "</p>";
									} else {
										total += "<p>"
												+ data[i].name
												+ " <a href='#' onclick=\"requestDeveloperInOrganization('"
												+ data[i].id + "','" + entId
												+ "')\">Invite</a></p>";
									}
								}
								document.getElementById("ideaDevelopers1").innerHTML = total;
								$('#ideaDevelopers1').toggle(500);
							}
						});
	}
	function requestDeveloperInOrganization(devId, entId) {
		$.getJSON("@{Application.requestIdeaDeveloperToOrganization()}", {
			'devId' : devId,
			'orgId' : entId
		}, function(data) {
			alert(data.res);
			getDevCanReqInOrg();
		});
	}

	function getDevCanReqInEnt() {
		var entId = document.getElementById('selavent3').options[document
				.getElementById('selavent3').selectedIndex].value
		document.getElementById('ideaDevelopers').innerHtml = "";
		$('#ideaDevelopers').hide(100);
		$
				.getJSON(
						"@{Application.getCanRequestIdeaDevelopersToEntity()}",
						{
							'entId' : entId
						},
						function(data) {
							if (data == null || data.length == 0) {
								alert("There are no developers you can invite to this entity");
							} else {
								var total = "";
								for ( var i = 0; i < data.length; i = i + 1) {
									if (data[i].id == -1) {
										total += "<p>" + data[i].name + "</p>";
									} else {
										total += "<p>"
												+ data[i].name
												+ " <a href='#' onclick=\"requestDeveloperInEntity('"
												+ data[i].id + "','" + entId
												+ "')\">Invite</a></p>";
									}
								}
								document.getElementById("ideaDevelopers").innerHTML = total;
								$('#ideaDevelopers').toggle(500);
							}
						});
	}

	function requestDeveloperInEntity(devId, entId) {
		$.getJSON("@{Application.requestIdeaDeveloperToEntity()}", {
			'devId' : devId,
			'entId' : entId
		}, function(data) {
			alert(data.res);
			getDevCanReqInEnt();
		});
	}
	function acceptReq(reqId) {
		$.getJSON("@{Application.acceptRequest()}", {
			'reqId' : reqId
		}, function(data) {
			alert(data.res);
		});
	}

	function createEntity() {
		var orgid = document.getElementById('selavorg').options[document
				.getElementById('selavorg').selectedIndex].value
		alert(current + "  " + orgid);
		if (document.getElementById("newEntName").value.length < 3) {
			alert('name req and atleast 3');
		} else {
			//public static void addEntity(String entityName, long orgId, long ideaDeveloper) {
			$.getJSON('@{Application.addEntity()}', {
				'entityName' : document.getElementById("newEntName").value,
				'orgId' : orgid,
				'ideaDeveloper' : current
			}, function(data) {
				alert(data.res);
				if (data.res == "Done Adding") {
					$('#createEntityDiv').toggle(1000);
				}
			});
		}

	}
	//public static void addSubEntity(String entityName, long entId, long ideaDeveloper)
	function createSubEntity() {
		if (document.getElementById("newSubEntName").value.length < 3) {
			alert('name req and atleast 3');
		} else {
			var orgid = document.getElementById('selavent').options[document
					.getElementById('selavent').selectedIndex].value
			$.getJSON('@{Application.addSubEntity()}', {
				'entityName' : document.getElementById("newSubEntName").value,
				'entId' : orgid,
				'ideaDeveloper' : current
			}, function(data) {
				alert(data.res);
				if (data.res == "Done Adding") {
					$('#createSubEntityDiv').hide(1000);
				}
			});
		}
	}
	//public static void deleteEntity(long entId, long ideaDeveloper)
	function delEntity() {
		var orgid = document.getElementById('selavent2').options[document
				.getElementById('selavent2').selectedIndex].value;
		$.getJSON('@{Application.deleteEntity()}', {
			'entId' : orgid,
			'ideaDeveloper' : current
		}, function(data) {
			alert(data.res)
			if (data.res == "DONE") {
				$('#deleteEntityDiv').hide(1000);
			}
		});
	}
</script>


<script type="text/javascript">
	
             function getTags(search){

                if(search!=""){
                    $(function() {
                        $.getJSON('@{QuickSearchRendering.autoComplete()}',{'search':search}, function(data) {
                            $("#searchMain").autocomplete({
                                source: data.tags.split("&")
                            });});

                    });
                }
            }


</script>
</head>
<body>

	<div id="container">
		<div id="header">
			<h1>
				<a href="/">MEGASOFT</a>
			</h1>
			<h2>Software ninjas</h2>
			<div class="clear"></div>
		</div>

		<div id="nav">
			<ul>


				<li><a href="@{UserProfile.SelfUserProfile()}">Home</a></li>
				<li><a href="@{BrowseController.BrowseOrganizations()}">organizations</a>
				</li>
				<li><a href="@{BrowseController.BrowseEntities()}">Entities</a>

				</li>
				<li><a href="@{BrowseController.BrowseTopics()}">Topics</a></li>
				<li><a href="@{BrowseController.BrowseIdeasPage()}">ideas</a></li>
				<li><a href="@{BrowseController.BrowseAll()}">Browse all</a>
				</li>

				<li><a href="@{Application.ousamaSprintOne()}" class="frame">Every
						Thing</a></li>

				<li><a href="@{AdvancedSearchController.AdvancedSearchView()}">Advanced
						Search</a>
				</li>
				<!--<li><a href="#">About</a>-->
				<li><a href="@{Secure.logout()}" title="logout">Logout</a></li>


				<li class="nav-search">
					<form name="searchFormMain" method="get" class="searchform"
						action="@{QuickSearchRendering.searchOnClickSearchButton()}"
						onsubmit="return validate_formMain ( );">
						<p>

							<input type="text" id="searchMain" size="24" value=""
								name="search" class="s"
								onkeyup="javascript:getTags(document.searchFormMain.searchMain.value);" />
							<!--                                                        <select name="filter" class="s">
								<option value="All">All</option>
								<option value="IdeaDevelopers">IdeaDevelopers</option>
								<option value="Tags">Tags</option>
								<option value="Organizations">Organizations</option>
								<option value="Entities">Entities</option>
								<option value="ActionPlans">ActionPlans</option>
								<option value="TopicsIdeas">Topic&Ideas</option>
							</select> -->
							<input type="submit" id="submitMain" name="submit"
								class="searchsubmit formbutton" value="Search" />

						</p>
					</form></li>
			</ul>
		</div>
		<div id="content">

			<div>
				<form name="GoMenuForm0" action="">
					<select id="GoMenu" name="GoMenu"
						style="left: 1px; top: 1px; width: 149px; height: 30px; font-family: 'Courier New'; font-size: 13px;"
						onchange="OnGoMenuFormLink(this)">
						<option selected>Select a link</option>
						<option class="_self" value="CreateEn">Create Entity</option>
						<option class="_self" value="CreateSub">Create Sub Entity</option>
						<option class="_self" value="DelEn">Delete Entity</option>

						<option class="_self" value="CheckInviteOrg">Check
							Invitations Sent To One Of your Organizations Or Entities</option>
						<option class="_self" value="CheckInviteDev">Check
							Invitations Sent To you by Organizations Or Entities</option>
						<option class="_self" value="InviteDevToEntity">Invite
							Idea Developer to One Of your Entities</option>
						<option class="_self" value="InviteDevToOrganization">
							Invite Idea Developer to One Of your Organizations</option>
					</select>

				</form>
			</div>
			<br />
			<div id="createEntityDiv"></div>

			<div id="createSubEntityDiv"></div>

			<div id="deleteEntityDiv"></div>

			<div id="orgRequestDiv"></div>

			<div id="devRequestDiv"></div>

			<div id="devCanDivInEnt"></div>

			<div id="devCanDivInOrg"></div>
		</div>
		<div id="page-intro"></div>
		<div id="body">
			<div id="footerplacement"
				style="height: 328px; width: 0px; float: right;"></div>

			#{doLayout /}
			<div class="clear"></div>
		</div>
	</div>
	<!-- Notification bar  start here -->
	<div id="footpanel">
		<ul id="mainpanel">
			<li><a href="#" class="profile">View Profile <small>View
						Profile</small> </a></li>

			<li><a href="#" class="editprofile">Edit Profile <small>Edit
						Profile</small> </a></li>
			<li><a href="#" class="contacts">Contacts <small>Contacts</small>
			</a></li>
			<li><a href="#" class="messages">Messages (10) <small>Messages</small>
			</a></li>

			<li><a href="#" class="playlist">Play List <small>Play
						List</small> </a></li>
			<li><a href="#" class="videos">Videos <small>Videos</small>
			</a></li>
			<li><input type="button" id="NotificationBTN"
				value="Show notifications popup "
				onclick="javascript:showNotificationsNotification()" /></li>
			<li id="alertpanel"><a href="#"
				onClick="javascript:showNotificationsID()" class="alerts">Alerts</a>
				<div id="notificationS" class="subpanel"></div></li>

			<li id="chatpanel"><a href="#" class="chat"
				onClick="javascript:updateList()">Friends (<strong>18</strong>)
			</a>
				<div class="subpanel">
					<h3>
						<span>&ndash; </span>Friends Online
					</h3>
					<ul>
						<li><span>Family Members</span></li>

						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

						<li><span>Other Friends</span></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>
						<li><a href="#"><img
								src="../../../public/images/chat-thumb.gif" alt="" /> Your
								Friend</a></li>

					</ul>
				</div></li>
		</ul>
	</div>
	<div id="two" class="jGrowl bottom-left">
		<div class="jGrowl-notification"></div>
	</div>
	<!-- Notification bar  end here -->
	<div id="footer">

		<p>&copy; Megasoft 2011. Website Design by alot of PPL isA</p>
	</div>
	<script type="text/javascript">
		function validate_formMain() {
			valid = true;

			if (document.searchFormMain.searchMain.value == "") {
				alert("Please fill in the word to search for");
				valid = false;
			}

			return valid;
		}
	</script>


</body>
</html>

<head>
<script>
	function vis() {

		$.getJSON('@{Application.changeOrgVisibility()}', {
			'orgId' : '${orgId}',
			'visibility' : $("select[id$='visibilities'] : selected").text()
		}, function(data) {
			alert(data.box);
		})
	}

	function requestTopic() {
		$('#topicrequest').show("medium");
		$('#previousD').remove();
		$('#nextD').remove();
		draftId = -1
	}

	function requestTopicDraft(x) {
		$
				.getJSON(
						'@{Application.getDrafts()}',
						{
							'orgId' : '${orgId}',
							'x' : x
						},
						function(data) {
							//  alert(data.size);
							$('#previousD').remove();
							$('#nextD').remove();

							original = document.getElementById("topicrequest").innerHTML;

							prevDiv = "<p><Button id=\"previousD\" onclick=\"javascript:requestTopicDraft("
									+ (x - 1) + ")\"> Previous </Button>"
							nextDiv = "<Button id=\"nextD\" onclick=\"javascript:requestTopicDraft("
									+ (x + 1) + ")\"> Next </Button>";

							if (data.size == 0) {
								$('#topicrequest').hide();
								draftId = -1;
							}

							else if (data.size == 1)
								document.getElementById("topicrequest").innerHTML = original;

							else {
								if (x == 0)
									document.getElementById("topicrequest").innerHTML = nextDiv
											+ original;

								else {
									if (x == data.size - 1)
										document.getElementById("topicrequest").innerHTML = prevDiv
												+ original;

									else
										document.getElementById("topicrequest").innerHTML = prevDiv
												+ nextDiv + original;
								}
							}
							document.getElementById("topicTitleReq").value = data.title;
							document.getElementById("topicBodyReq").value = data.description;
							draftId = data.id;
						});
		$('#topicrequest').show("medium");
	}

	function discardButton() {
		if (draftId != -1) {
			$.ajax({
				type : "POST",
				url : '@{Application.removeDraft()}',
				data : {
					'draftId' : draftId
				}
			});
		}
		document.getElementById("topicTitleReq").value = "";
		document.getElementById("topicBodyReq").value = "";
		$('#topicrequest').hide("slow");
		draftsButton();
	}

	function sendReq() {
		var titleEntered = document.getElementById("topicTitleReq").value;
		var bodyEntered = document.getElementById("topicBodyReq").value;

                 if (titleEntered=="" || bodyEntered=="") {
			alert("Title and Body are Required")
		} else {
			$.ajax({
				type : "POST",
				url : '@{Application.topicRequestOrg()}',
				data : {
					'title' : titleEntered,
					'description' : bodyEntered,
					'orgId' : '${orgId}'
				}
			});

			//alert("tamam kda");
			requestSaved();
			discardButton();
			draftsButton();
		}
	}

	function requestSaved() {
		$.getJSON('@{Application.topicRequestOrgSaved(orgId)}', function(data) {
			//alert(data.RequestsinOrg);

		});
	}
        function validate(input){
        var isAlphaNeumeric =/^[0-9a-zA-Zs ]+$/;
        var isAllSpace = /^[\s ]*$/;
        if(!isAlphaNeumeric.test(input) || isAllSpace.test(input)){
            return false;
        }else{
            return true;
        }
    }

	function draftButton() {
		if (draftId != -1) {
			$.ajax({
				type : "POST",
				url : '@{Application.removeDraft()}',
				data : {
					'draftId' : draftId
				}
			});
		}
		var titleEntered = document.getElementById("topicTitleReq").value;
		var bodyEntered = document.getElementById("topicBodyReq").value;

                 if (titleEntered=="" && bodyEntered=="") {
			alert("Title or Body are Required");
		} else {
			$.ajax({
				type : "POST",
				url : '@{Application.saveDraft()}',
				data : {
					'title' : titleEntered,
					'description' : bodyEntered,
					'orgId' : '${orgId}'
				}
			});
			//alert(titleEntered+" "+bodyEntered);
			// alert("drafted it");
			discardButton();
			checkDraftedTopicRequest();
			draftsButton();
		}
	}

	function checkDraftedTopicRequest() {
		$.getJSON('@{Application.checkDraftSaved()}', function(data) {
			// alert(data.draftedTitle + " " + data.draftedBody);

		});
	}

	function buttonsChecks() {
		$.getJSON('@{Application.checkForButtons(orgId)}', function(data) {
			if (data.leaders) {
				$('#topReqBtn').hide();
				$('#topReqchkBtn').show();
                                $('#createTopicLink').show();
                                $('#showDuplicatedButton').slideDown();
			} else {
				$('#topReqBtn').show();
				$('#topReqchkBtn').hide();
				draftsButton();
			}
		});
	}

	function draftsButton() {
		$.getJSON('@{Application.draftsButtons(orgId)}', function(data) {
			if (!data.draftsEmpty) //data is NOT empty
			{
				$('#drafts').show();
			} else {
				$('#drafts').hide();
			}
		});
	}

	function checkTopicReqs(x) {
		$('#requests').toggle();
		reqs(x);
	}
	function reqs(x) {
		document.getElementById("requests").innerHTML = "";

		$
				.getJSON(
						'@{Application.getRequests()}',
						{
							'orgId' : '${orgId}',
							'x' : x
						},
						function(data) {
							//alert(x);
							//alert(data.x);
                                                        var title = data.title;
                                                        var description = data.description;
							newDiv = "<div> <h1>Proposed Topic Title : </h1> <h3>&nbsp;&nbsp;&nbsp;"
									+ data.title
									+ "</h3> \n\
                                                       <h1>Proposed Topic Body : </h1><h3>&nbsp;&nbsp;&nbsp;"
									+ data.description
									+ "</h3>\n\
                                                       <h1>Proposed By : </h1><h3>&nbsp;&nbsp;&nbsp;"
									+ data.name + "</h3>";
							btnDiv = "<p><Button id=\"approve\" onclick=\'javascript:approve("
									+ data.id
									+ ","
									+ x
									+ ","
									+ data.size
                                                                        +","
                                                                        +"\""+title+"\""
                                                                        +",\""+description
                                                                        +"\")\'> Approve </Button>\n\
                                                                  <Button id=\"reject\" onclick=\"javascript:reject("
									+ data.id
									+ ","
									+ x
									+ ","
									+ data.size
									+ ")\"> Reject </Button>  <\p>";

							prevDiv = "<p><Button id=\"previous\" onclick=\"javascript:reqs("
									+ (x - 1) + ")\"> Previous </Button>"
							nextDiv = "<Button id=\"next\" onclick=\"javascript:reqs("
									+ (x + 1) + ")\"> Next </Button>";

							if (data.size == 0)
								document.getElementById("requests").innerHTML = "No Requests are here nw!";

							else if (data.size == 1)
								document.getElementById("requests").innerHTML += newDiv
										+ btnDiv;

							else {
								if (x == 0)
									document.getElementById("requests").innerHTML += nextDiv
											+ newDiv + btnDiv;

								else {
									if (x == data.size - 1)
										document.getElementById("requests").innerHTML += prevDiv
												+ newDiv + btnDiv;

									else
										document.getElementById("requests").innerHTML += prevDiv
												+ nextDiv + newDiv + btnDiv;
								}
							}

						});
	}

	var draftId = -1;

	function reject(i, x, size) {
		$.ajax({
			type : "POST",
			url : '@{Application.reqRej()}',
			data : {
				'reqId' : i
			}
		});
		if (size - 1 == x)
			reqs(x - 1);
		else
			reqs(x);
	}

	function approve(i,x,size, title, description) {
		displayCreateDivReq(title, description);
                reject(i,x,size);
    }
</script>

<script type="text/javascript">
	$(document)
			.ready(
					function display2() {

						$
								.getJSON(
										'@{Application.canFollowOrganization()}',
										{
											'organizationId' : '${orgId}'
										},
										function(data) {

											if (data.followOrganization == "you are already a follower") {
												document
														.getElementById('follow').style.visibility = 'hidden';
												document
														.getElementById('unfollow').style.visibility = 'visible';
											} else {
												document
														.getElementById('unfollow').style.visibility = 'hidden';
												document
														.getElementById('follow').style.visibility = 'visible';
											}
										});
					});
</script>

<script type="text/javascript">
	function followOrganization() {
		$.getJSON('@{Application.followOrganization()}', {
			'organizationId' : '${orgId}'
		}, function(data) {
			document.getElementById('follow').style.visibility = 'hidden';
			document.getElementById('unfollow').style.visibility = 'visible';
		});
	}
</script>

<script type="text/javascript">
	function unfollowOrganization() {

		$.getJSON('@{Application.unfollowOrganization()}', {
			'organizationId' : '${orgId}'
		}, function(data) {
			document.getElementById('follow').style.visibility = 'visible';
			document.getElementById('unfollow').style.visibility = 'hidden';
		});
	}
</script>

<script type="text/javascript">

	var freeze = 0;
	var follow = 0;
	// var a = [document.getElementById("star1"), document.getElementById("star2"), document.getElementById("star3"), document.getElementById("star4"), document.getElementById("star5")]

	function mouseonimage(id) {

		for ( var i = 0; i < 5; i++) {
			a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
		}

		for ( var i = 0; i < id; i++) {

			a[i].src = "..\\..\\..\\public\\images\\redstar.png";
		}

	}

	function mouseoutimage() {

		for ( var i = 0; i < 5; i++) {
			a[i].src = "..\\..\\..\\public\\images\\star.png";
		}

		for ( var i = freeze; i < 5; i++) {

			a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
		}

	}

	/* function resetstars(){

		for(var i = 0; i < 5; i++) {
			a[i].src = "..\\..\\..\\public\\images\\disabledstar.png";
		}

		freeze = 0;
	} */

	function loadRate() {
		
		$.getJSON('@{TopicIdeaController.getOrganizationRating()}', {'organizationId':'${orgId}'},function(data){
			document.getElementById("currentRating").innerHTML=data.result;

		});

	

		$.getJSON('@{TopicIdeaController.alreadyRatedOrganization()}', {
			'organizationId' : '${orgId}'
		}, function(data) {
			freeze = data.result;
			mouseoutimage();

		});

	}

	function rateOrganization(rating) {

		$.getJSON('@{TopicIdeaController.rateOrganization()}', {
			'rate' : rating,
			'organizationId' : '${orgId}'
		}, function(data) {

			freeze = data.result;
			mouseoutimage();
		});
		
		loadRate();

	}
</script>

</head>